// TinyVoiceCardServer.cpp : Implementation of WinMain


#include "stdafx.h"
#include "resource.h"
#include "VoiceCardServer.h"
#include "TinyVoiceCardServer.h"

#include <stdio.h>

class CTinyVoiceCardServerModule : public CAtlServiceModuleT< CTinyVoiceCardServerModule, IDS_SERVICENAME >
{
public :
	DECLARE_LIBID(LIBID_TinyVoiceCardServerLib)
	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_TINYVOICECARDSERVER, "{26FE2EA7-AC1C-4EFB-B07F-F1CFBD0A67CA}")
	HRESULT InitializeSecurity() throw()
	{
		// TODO : Call CoInitializeSecurity and provide the appropriate security settings for 
		// your service
		// Suggested - PKT Level Authentication, 
		// Impersonation Level of RPC_C_IMP_LEVEL_IDENTIFY 
		// and an appropiate Non NULL Security Descriptor.

		return S_OK;
	}
	HRESULT PostMessageLoop();
	HRESULT PreMessageLoop(int nShowCmd);
	CVoiceCardServer m_server;
};

CTinyVoiceCardServerModule _AtlModule;



//
extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, 
                                LPTSTR /*lpCmdLine*/, int nShowCmd)
{
    return _AtlModule.WinMain(nShowCmd);
}


HRESULT CTinyVoiceCardServerModule::PostMessageLoop()
{
	// TODO: Add your specialized code here and/or call the base class

	HRESULT hr = CAtlServiceModuleT<CTinyVoiceCardServerModule,100>::PostMessageLoop();
	m_server.end();
	Sleep( 4000 );
	return hr;

	//return CAtlServiceModuleT<CTinyVoiceCardServerModule,100>::PostMessageLoop();
}

HRESULT CTinyVoiceCardServerModule::PreMessageLoop(int nShowCmd)
{

	m_status.dwControlsAccepted =m_status.dwControlsAccepted | SERVICE_ACCEPT_PAUSE_CONTINUE;
	HRESULT hr = __super::PreMessageLoop(nShowCmd);
	if (hr == S_FALSE) hr = S_OK;
	bool ret = m_server.init();

	if(ret == true)
		m_server.start();

	return hr;
	// TODO: Add your specialized code here and/or call the base class
	//return CAtlServiceModuleT<CTinyVoiceCardServerModule,100>::PreMessageLoop(nShowCmd);
}
